// 显示指定区域内容
function showSection(sectionId) {
    document.querySelectorAll('.section-content').forEach(section => {
        section.classList.add('hidden');
    });
    document.getElementById(`${sectionId}-section`).classList.remove('hidden');

    // 更新导航菜单活动状态
    document.querySelectorAll('nav a').forEach(link => {
        const target = link.getAttribute('href').substring(1);
        if (target === sectionId) {
            link.classList.add('bg-blue-50', 'text-blue-700');
            link.classList.remove('text-gray-600', 'hover:bg-gray-50', 'hover:text-gray-900');
        } else {
            link.classList.remove('bg-blue-50', 'text-blue-700');
            link.classList.add('text-gray-600', 'hover:bg-gray-50', 'hover:text-gray-900');
        }
    });
}

// 格式化文件大小
function formatFileSize(bytes) {
    if (bytes === 0) return '0 Bytes';
    const k = 1024;
    const sizes = ['Bytes', 'KB', 'MB', 'GB'];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}

// 显示加载状态
function showLoading(element) {
    element.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 加载中...';
    element.disabled = true;
}

// 隐藏加载状态
function hideLoading(element, originalText) {
    element.textContent = originalText;
    element.disabled = false;
}

// 导出工具函数
export {
    showSection,
    formatFileSize,
    showLoading,
    hideLoading
};